package org.example.api;

/**
 * @author
 * @date 2021-4-16 11:37
 */
public class R<T> {
    private Integer code;
    private String msg;
    private T data;
    public R(){

    }
    public R(Builder<T> builder) {
        this.code = builder.code;
        this.msg = builder.msg;
        this.data = builder.data;
    }

    public static class Builder<T>{
        private Integer code;
        private String msg;
        private T data;

        public Builder() {
        }
        public R buildCustomize(Integer code,String msg) {
            this.code = code;
            this.msg = msg;
            return new R(this);
        }
        public R buildCustomize(String msg) {
            this.code = -1;
            this.msg = msg;
            return new R(this);
        }
        public R buildOk() {
            this.code = 200;
            this.msg ="SUCCESS";
            return new R(this);
        }
        public R buildFail(){
            this.code = -1;
            this.msg = "FAILURE";
            return new R(this);
        }
        public Builder setData(T data) {
            this.data = data;
            return this;
        }
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }
}
